<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        border: solid;
        width: 400px;
        padding: 20px;
        margin: 10px;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <button id="btn">X</button>
      text...
    </div>

    <div class="box">
      <button id="btn">X</button>
      text...
    </div>

    <div class="box">
      <button id="btn">X</button>
      text...
    </div>
    <script>
      document.querySelectorAll(".box button").forEach((el) => {
        el.onclick = function () {
          // el.parentElement.style.display = "none";
          el.parentElement.remove();
        };
      });
    </script>
  </body>
</html>
